<?php

namespace app\index\model;

use think\Model;

class Code extends Model
{
    public $p = 1;
    public $limit = 10;
    public $map = [];
    public $fields = '*';
    public $data = [];
    public $order = 'update_time desc,ID desc';

    public function initialize()
    {
        parent::initialize();
        $this->map['status'] = ['neq','0'];
        $p = input('param.p',1);
        $limit = input('param.limit',10);
        $this->p = $p?$p:1;
        $this->limit = $limit?$limit:10;
    }

    public function get_one()
    {
        return $this->field($this->fields)->where($this->map)->find();
    }

    public function get_list()
    {
        return $this->field($this->fields)->where($this->map)->order($this->order)->select();
    }

    public function add(){
        return $this->insertGetId($this->data);
    }

    public function modify()
    {
        return $this->where($this->map)->update($this->data);
    }

    public function del()
    {
        return $this->where($this->map)->update($this->data);
    }
}